package com.ruoyi.teach.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.teach.domain.NbCourse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.teach.domain.NbCourseAttribute;
import com.ruoyi.teach.service.INbCourseAttributeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程属性Controller
 * 
 * @author ruoyi
 * @date 2021-12-08
 */
@RestController
@RequestMapping("/teach/course_attribute")
public class NbCourseAttributeController extends BaseController
{
    @Autowired
    private INbCourseAttributeService nbCourseAttributeService;

    /**
     * 查询课程属性列表
     */
    @PreAuthorize("@ss.hasPermi('teach:course_attribute:list')")
    @GetMapping("/list")
    public TableDataInfo list(NbCourseAttribute nbCourseAttribute)
    {
        startPage();
        List<NbCourseAttribute> list = nbCourseAttributeService.selectNbCourseAttributeList(nbCourseAttribute);
        return getDataTable(list);
    }

    /**
     * 导出课程属性列表
     */
    @PreAuthorize("@ss.hasPermi('teach:course_attribute:export')")
    @Log(title = "课程属性", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NbCourseAttribute nbCourseAttribute)
    {
        List<NbCourseAttribute> list = nbCourseAttributeService.selectNbCourseAttributeList(nbCourseAttribute);
        ExcelUtil<NbCourseAttribute> util = new ExcelUtil<NbCourseAttribute>(NbCourseAttribute.class);
        util.exportExcel(response, list, "课程属性数据");
    }

    /**
     * 获取课程属性详细信息
     */
    @PreAuthorize("@ss.hasPermi('teach:course_attribute:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(nbCourseAttributeService.selectNbCourseAttributeById(id));
    }

    /**
     * 新增课程属性
     */
    @PreAuthorize("@ss.hasPermi('teach:course_attribute:add')")
    @Log(title = "课程属性", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NbCourseAttribute nbCourseAttribute)
    {
        return toAjax(nbCourseAttributeService.insertNbCourseAttribute(nbCourseAttribute));
    }

    /**
     * 修改课程属性
     */
    @PreAuthorize("@ss.hasPermi('teach:course_attribute:edit')")
    @Log(title = "课程属性", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NbCourseAttribute nbCourseAttribute)
    {
        return toAjax(nbCourseAttributeService.updateNbCourseAttribute(nbCourseAttribute));
    }

    /**
     * 删除课程属性
     */
    @PreAuthorize("@ss.hasPermi('teach:course_attribute:remove')")
    @Log(title = "课程属性", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(nbCourseAttributeService.deleteNbCourseAttributeByIds(ids));
    }
    /**
     * 通过课程id查询属性
     */
    @PreAuthorize("@ss.hasPermi('teach:course_attribute:list')")
    @GetMapping("/attrbute")
    public AjaxResult attrbute(NbCourse course){
        List<NbCourseAttribute> list = nbCourseAttributeService.selectNbCourseAttributeBycId(course);
        return AjaxResult.success(list.get(0));
    }

}
